import { request } from '@/utils/request'
import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'

// 实现密码登陆
const MobileByPassword = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', { mobile, password })
}
// 发送短信验证码
const MobileByCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('/code', 'GET', { mobile, type })
}
// 短信登陆
const MobileByLogin = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

// 获取个人信息
const getUserInfo = () => request<UserInfo>('/patient/myUser')

// 获取患者列表
const getPatientList = () => request<PatientList>('/patient/mylist', 'get')

// 添加患者信息
const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)

// 编辑患者信息
const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

// 删除患者信息

const delPatient = (id: string) => request(`/patient/del/${id}`, 'DELETE')

// 获取患者详情
const getPatient = (id: string) =>
  request<Patient>(`/patient/info/${id}`, 'GET')

export {
  MobileByPassword,
  MobileByCode,
  MobileByLogin,
  getUserInfo,
  getPatientList,
  addPatient,
  editPatient,
  delPatient,
  getPatient
}
